<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>我的请假</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
		
		<!--表格开始-->
        <table class="layui-hide" id="noticeTable" lay-filter="noticeTable"></table>
        <script type="text/html" id="noticeToolBar">
			<a class="layui-btn layui-btn-sm" lay-event="add">请假</a>
            <a class="layui-btn layui-btn-sm layui-btn-danger data-count-delete" lay-event="batchdelete">批量取消</a>
        </script>
		<script type="text/html" id="noticeTableBar">
		    <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">取消</a>
		</script>
		<!--表格结束-->
		
		<!--添加和修改的弹出层开始-->
		<div id="addOrUpdateDiv" style="display: none;padding: 0.3125rem">
			<form class="layui-form layui-row" method="post" id="dataFrm" lay-filter="dataFrm">
					<div class="layui-form-item">
						<label class="layui-form-label">请假原因</label>
						<div class="layui-input-block">
							<input type="text" name="content" lay-verify="required" autocomplete="off" placeholder="请输入请假原因" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">请假天数</label>
						<div class="layui-input-block">
							<input type="text" name="days" lay-verify="required" autocomplete="off" placeholder="请输入请假天数" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-input-block" style="text-align: center;">
							<a class="layui-btn " lay-submit=""  lay-filter="doSubmit"><label class="layui-icon layui-icon-release"></label>申请</a>
							<a class="layui-btn layui-btn-warm" onclick="javascript:$('#dataFrm')[0].reset()" lay-filter="data-search-btn"><label class="layui-icon layui-icon-refresh"></label>重置</a>
						</div>
					 </div>
			</form>
		</div>
		<!--添加和修改的弹出层结束-->
    </div>
</div>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
<script src="../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
<script src="../../lib/common/common.js" charset="utf-8"></script>

<script>
    layui.use(['form', 'table','laydate','layer','wangEditor'], function () {
        var form = layui.form;
        var table = layui.table;
		var laydate=layui.laydate;
		var layer=layui.layer;
		var wangEditor = layui.wangEditor;
		
      var tableIns=table.render({
            elem: '#noticeTable',
            url: api+'leave/LookMylEAVE',
			toolbar:"#noticeToolBar",
			cellMinWidth:true,
            cols: [[
                {type: "checkbox",  fixed: "left",width: 100},
                {field: 'activitiId', title: '请假id', align: "center"},
                {field: 'days',  title: '请假天数', align: "center"}, 
                {field: 'content',  title: '请假原因', align: "center",width: 440},
                {field: 'createTime',  title: '请假时间', align: "center"},
                {field: 'state',  title: '状态', align: "center",width: 140,templet: function(d){
                	var html="";
                	if(d.state == 1){
                		html="<font color=red>提交</font>"
                	}else if(d.state == 2){
                		html="<font color=black>审批中</font>"
                	}else if(d.state == 3){
                		html="<font color=blue>审批通过</font>"
                	}else if(d.state == 4){
                		html="<font color=blue>审批失败</font>"
                	}
                	return html;
                }},
                {title: '操作', templet: '#noticeTableBar', fixed: "right", align: "center",width:190}
            ]],
            page: true
        });

		//监听表头的事件
		table.on('toolbar(noticeTable)', function(obj){
		  var checkStatus = table.checkStatus(obj.config.id);
		  switch(obj.event){
		    case 'batchdelete':
				batchdelete();
		    break;
			case 'add':
				openAddNotice();
			break;
		  };
		});
		
		//监听行数据的事件
        table.on('tool(noticeTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm('真的删除这条数据么', function (index) {
					$.post(api+"leave/DeletelEAVE",{ids:data.activitiId},function(res){
						layer.msg(res.msg);
						obj.del();
						layer.close(index);
						tableIns.reload();
					})
                });
            }
			
        });
		
		
		
		//打开请假的弹层
		var mainIndex;
		var url;  //动态的url
		function openAddNotice(){
			mainIndex=layer.open({
				type:1,
				title:'请假',
				content:$("#addOrUpdateDiv"),
				area:['450px','300px'],
				success:function(index){
					url=api+"leave/startProcess";
					//重置表单
					$("#dataFrm")[0].reset();
					 editor.txt.html("");
				}
			});	
		}
		var data = form.val("dataFrm",data);
		console.log(data);
		//提交数据
		form.on("submit(doSubmit)",function(data){
			var params= $("#dataFrm").serialize();
			$.post(url,params, function(res){
				layer.msg(res.msg);
				if(res.code==200){
					tableIns.reload();
				}
				layer.close(mainIndex);
			})
			return false;
		})
		
		
		//批量删除
		function batchdelete(){
			var checkStatus = table.checkStatus('noticeTable'); //idTest 即为基础参数 id 对应的值
			var data=checkStatus.data;
			var length=checkStatus.data.length;
			console.log(checkStatus.data) //获取选中行的数据
			console.log(checkStatus.data.length) //获取选中行数量，可作为是否有选中行的条件
			if(length==0){
				layer.msg("请选中你要撤回的请假");
			}else{
				layer.confirm('真的撤回选择中这些的请假么?', function (index) {
					var params="";
					$.each(data,function(index,item){
						if(index==0){
							params+="ids="+item.activitiId;
						}else{
							params+="&ids="+item.activitiId;
						}
					});
					$.post(api+"leave/DeletelEAVE",params,function(res){
						layer.msg(res.msg);
						tableIns.reload();
						layer.close(index);
					})
				});
			}
		}
		var editor = new wangEditor('#content');
		editor.customConfig.uploadImgServer = "../api/upload.json";
		editor.customConfig.uploadFileName = 'image';
		editor.customConfig.pasteFilterStyle = false;
		editor.customConfig.uploadImgMaxLength = 5;
		editor.customConfig.customAlert = function (info) {
		    layer.msg(info);
		};
		editor.create();
		
    });
</script>
</body>
</html>